package com.muyu.danmo.service.impl;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.system.domain.SysUser;
import com.muyu.danmo.domain.DanmoInformationBasic;
import com.muyu.danmo.mapper.DanmoInformationBasicMapper;
import com.muyu.danmo.service.IDanmoInformationBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 基本信息Service业务层处理
 * 
 * @author yangle
 * @date 2025-01-08
 */
@Service
public class DanmoInformationBasicServiceImpl implements IDanmoInformationBasicService
{
    @Autowired
    private DanmoInformationBasicMapper danmoInformationBasicMapper;

    /**
     * 查询基本信息
     * 
     * @param id 基本信息主键
     * @return 基本信息
     */
    @Override
    public DanmoInformationBasic selectDanmoInformationBasicById(Long id)
    {
        return danmoInformationBasicMapper.selectDanmoInformationBasicById(id);
    }

    /**
     * 查询基本信息列表
     * 
     * @param danmoInformationBasic 基本信息
     * @return 基本信息
     */
    @Override
    public List<DanmoInformationBasic> selectDanmoInformationBasicList(DanmoInformationBasic danmoInformationBasic)
    {
        return danmoInformationBasicMapper.selectDanmoInformationBasicList(danmoInformationBasic);
    }

    /**
     * 新增基本信息
     * 
     * @param danmoInformationBasic 基本信息
     * @return 结果
     */
    @Override
    public Result insertDanmoInformationBasic(DanmoInformationBasic danmoInformationBasic)
    {
        extracted(danmoInformationBasic);
        danmoInformationBasic.setCreateTime(DateUtils.getNowDate());
        danmoInformationBasicMapper.insertDanmoInformationBasic(danmoInformationBasic);
        return Result.success(danmoInformationBasic,"新增成功");
    }

    private void extracted(DanmoInformationBasic danmoInformationBasic) {
        SysUser sysUser = new SysUser();
        sysUser.setUserId(danmoInformationBasic.getUserId());
        sysUser.setNickName(danmoInformationBasic.getNickname());
        sysUser.setAvatar(danmoInformationBasic.getAvatar());
        danmoInformationBasicMapper.updateSysUser(sysUser);
    }

    /**
     * 修改基本信息
     * 
     * @param danmoInformationBasic 基本信息
     * @return 结果
     */
    @Override
    public Result updateDanmoInformationBasic(DanmoInformationBasic danmoInformationBasic)
    {
        extracted(danmoInformationBasic);
        danmoInformationBasic.setUpdateTime(DateUtils.getNowDate());
        danmoInformationBasicMapper.updateDanmoInformationBasic(danmoInformationBasic);
        return Result.success(danmoInformationBasic,"修改成功");
    }

    /**
     * 批量删除基本信息
     * 
     * @param ids 需要删除的基本信息主键
     * @return 结果
     */
    @Override
    public Result deleteDanmoInformationBasicByIds(Long[] ids)
    {
        danmoInformationBasicMapper.deleteDanmoInformationBasicByIds(ids);
        return Result.success(ids,"删除成功");
    }

    /**
     * 删除基本信息信息
     * 
     * @param id 基本信息主键
     * @return 结果
     */
    @Override
    public Result deleteDanmoInformationBasicById(Long id)
    {
         danmoInformationBasicMapper.deleteDanmoInformationBasicById(id);
     return    Result.success(id,"删除成功");
    }

    @Override
    public DanmoInformationBasic getInfo(Long userid) {
        return danmoInformationBasicMapper.getInfo(userid);
    }

    @Override
    public List<DanmoInformationBasic> selectInformationBasicList(List<Long> longs) {
        return danmoInformationBasicMapper.selectInformationBasicList(longs);
    }
}
